package com.only4play.productcenter.infrastructre.constants;

import com.only4play.common.constants.BaseEnum;

import java.util.Optional;

/**
 * 错误码 1011001
 * 10 系统 领域
 * 11 模块 应用
 * 001 错误编码
 */
public enum ProductErrorCode implements BaseEnum<ProductErrorCode> {

  PRODUCT_NAME_EMPTY(1001001, "商品名称不能为空"),
  GOODS_HAS_IN(1001002,"商品已在库"),
  GOODS_HAS_OUT(1001003,"商品已出库"),
    ;

  ProductErrorCode(Integer code, String name) {
    this.code = code;
    this.name = name;
  }

  private Integer code;
  private String name;

  @Override
  public Integer getCode() {
    return this.code;
  }

  @Override
  public String getName() {
    return this.name;
  }

  public static Optional<ProductErrorCode> of(Integer code) {
    return Optional.ofNullable(BaseEnum.parseByCode(ProductErrorCode.class, code));
  }

}
